Skip to content

Add adc_ladder() factory for ADC resistor-ladder binary inputs#78

Open
teancom wants to merge 2 commits into
OpenDisplay:mainfrom
teancom:feat/adc-ladder
Open

Add adc_ladder() factory for ADC resistor-ladder binary inputs#78
teancom wants to merge 2 commits into
OpenDisplay:mainfrom
teancom:feat/adc-ladder

Conversation

@teancom
Copy link
Copy Markdown
Contributor

@teancom teancom commented Jun 2, 2026

Matching PR to OpenDisplay/Firmware#35, this adds support for configs of analog buttons. Tested live on an XTEINK X4, and I tried to make it as generic as possible. As always, let me know if something doesn't look right / should be architected differently, I'm still learning (obvs!) so any/all feedback is very welcome.

Robot's commit message:

ADC resistor-ladder buttons (input_type=2) share one ADC pin and are distinguished by voltage. adc_ladder() packs (N, id_base) + (N+1) strictly-descending LE uint16 thresholds into BinaryInputs.reserved[14], matching the firmware's registerAdcLadder decode byte-for-byte.

Validation mirrors the firmware contract so this helper can't build a config the device would silently drop:

  • 2..6 thresholds (N = 1..5; reserved[14] holds at most N+1=6)
  • thresholds strictly descending, each a uint16
  • button_data_byte_index 0..10 (index into the 11-byte MSD block)
  • id_base >= 0 and last id <= 7 (button id is a 3-bit report field)

Adds BinaryInputType enum and tests pinning the wire contract plus every rejection branch.

@teancom teancom requested a review from g4bri3lDev as a code owner June 2, 2026 18:18
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

teancom and others added 2 commits June 4, 2026 12:09
ADC resistor-ladder buttons (input_type=2) share one ADC pin and are
distinguished by voltage. adc_ladder() packs (N, id_base) + (N+1)
strictly-descending LE uint16 thresholds into BinaryInputs.reserved[14],
matching the firmware's registerAdcLadder decode byte-for-byte.

Validation mirrors the firmware contract so this helper can't build a
config the device would silently drop:
  - 2..6 thresholds (N = 1..5; reserved[14] holds at most N+1=6)
  - thresholds strictly descending, each a uint16
  - button_data_byte_index 0..10 (index into the 11-byte MSD block)
  - id_base >= 0 and last id <= 7 (button id is a 3-bit report field)

Adds BinaryInputType enum and tests pinning the wire contract plus every
rejection branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Matches firmware OpenDisplay#35 review: input_type == 2 is reserved for the
host-side switch feature. Add SWITCH = 2 to model the reservation and
renumber ADC_LADDER to 3. Wire layout is otherwise unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant